package com.entity;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class Car implements InitializingBean, BeanPostProcessor {
    @Value("${car.color}")
    private String color;

    public Car(){
        System.out.println("....car construct.....invoke ");
    }

    @PostConstruct
    public void postConstruct(){
        System.out.println("....postConstruct.....invoke");
        System.out.println(this.color);
    }

    public void initMethod(){
        System.out.println("....initMethod.....invoke");
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println(".... initializingBean afterPropertiesSet.....invoke");
    }
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        if(o instanceof Car){
            System.out.println("....car BeanPostProcessor postProcessBeforeInitialization.....invoke");
        }
        System.out.println("bean before:" + o);
        return o;
    }

    public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
        if(o instanceof Car){
            System.out.println("....car BeanPostProcessor postProcessAfterInitialization.....invoke");
        }
        System.out.println("bean after:" + o);
        return o;
    }

    @Override
    public String toString() {
        return "Car{" +
                "color='" + color + '\'' +
                '}';
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
}
